<template>
  <view class="cart-container">
    <!-- 加载状态 -->
    <view v-if="loading" class="loading-container">
      <u-loading-icon mode="spinner" size="30"></u-loading-icon>
      <text class="loading-text">正在加载购物车...</text>
    </view>
    
    <!-- 错误状态 -->
    <view v-else-if="error" class="error-container">
      <u-empty mode="error" icon="/static/img/error.png">
        <text class="error-text">{{ error }}</text>
        <button class="retry-btn" @click="fetchCartData">重试</button>
      </u-empty>
    </view>
    
	<!-- 空购物车状态 -->
     <template v-else-if="cartList.length === 0">
       <u-empty mode="car" icon="/static/img/购物车为空.png">
         <view @click="toshouye">随便逛逛></view>
       </u-empty>
       
       
     </template>
    
    <!-- 购物车内容 -->
    <template v-else>

      
      <!-- 购物车列表 -->
       <view class="cart-list">
         <!-- 店铺分组 -->
         <view class="store-section" v-for="(store, storeIndex) in groupedStores" :key="storeIndex">
			<!-- 店铺头部 -->
            <view class="store-header">
              <view class="store-info">
                <u-checkbox-group @change="(value) => toggleStore(storeIndex, value.includes(storeIndex))">
                  <u-checkbox :name="storeIndex" :checked="store.checked"></u-checkbox>
                </u-checkbox-group>
                <text class="store-name" @click="goToStore(store.name)">{{ store.name }} ›</text>
              </view>
               <text class="get-coupon-btn" @click="goToCouponCenter">领券</text>
            </view>
           
           <!-- 满减活动信息 -->
           <view class="promotion-info" v-if="store.promotion">
             <text class="promotion-tag">满减</text>
             <scroll-view class="promotion-scroll" scroll-x="true">
               <text class="promotion-desc">{{ store.promotion }}</text>
             </scroll-view>
           </view>
           
           <!-- 店铺商品列表 -->
           <view 
             class="product-item"
             v-for="(item, index) in store.items"
             :key="item.id"
             @touchstart="handleTouchStart($event, item.id)"
             @touchmove="handleTouchMove($event, item.id)"
             @touchend="handleTouchEnd(item.id)"
           >
            <!-- 可滑动内容区域 -->
              <view class="item-content" :style="{ transform: `translateX(${item.offsetX}px)` }">
                <!-- 商品选择框 -->
                <u-checkbox-group @change="(value) => toggleProduct(item.id, value.includes(item.id))">
                  <u-checkbox :name="item.id" :checked="item.checked"></u-checkbox>
                </u-checkbox-group>

               <!-- 商品图片 -->
               <image class="item-image" :src="item.image" mode="aspectFill"></image>

               <!-- 商品信息 -->
               <view class="item-info">
                 <text class="item-title">{{ item.name }}</text>
                 <text class="item-spec" v-if="item.spec">{{ item.spec }}</text>
                <!-- <text class="item-unit" v-if="item.unit">{{ item.unit }}</text> -->
				<view>
					<text class="item-price">¥{{ item.lastprice.toFixed(2) }}</text>
					<text class="item-cartprice">¥{{ item.cartprice.toFixed(2) }}</text>
				</view>
               </view>

            <!-- 数量操作 -->
                <view class="item-actions">
                  <view class="quantity-control">
                    <text class="quantity-btn" @click="decreaseQuantity(item.id)">−</text>
                    <input 
                      class="quantity-input" 
                      :value="item.count" 
                      @input="onQuantityInput($event, item.id)"
                      @blur="onQuantityBlur(item.id)"
                      type="number"
                      min="1"
                    />
                    <text class="quantity-btn" @click="increaseQuantity(item.id)">+</text>
                  </view>
                </view>
             </view>

             <!-- 删除按钮 -->
             <view
               class="delete-btn"
               :style="{ transform: `translateX(${item.offsetX}px)` }"
               @click.stop="showDeleteConfirm(item.id)"
             >
               删除
             </view>
           </view>
         </view>
       </view>

      <!-- 底部结算栏 -->
      <view class="footer-bar">
        <view class="footer-left">
                     <u-checkbox-group @change="(value) => handleSelectAll(value.includes('all'))">
             <u-checkbox :name="'all'" :checked="selectAll"></u-checkbox>
           </u-checkbox-group>
        </view>
                 <view class="footer-right">
           <text class="total-price">总计:¥{{ totalPrice.toFixed(2) }}</text>
           <text class="discount">优惠减:¥{{ discount.toFixed(2) }}</text>
           <text class="discount-detail" @click="showDiscountDetail">优惠明细</text>
           <button class="submit-btn" :disabled="selectedCount === 0" @click="handleCheckout">
             去结算
           </button>
         </view>
      </view>

             <!-- 删除确认弹窗 -->
       <view class="delete-modal" v-if="showDeleteModal">
         <view class="modal-overlay" @click="cancelDelete"></view>
         <view class="modal-content">
           <view class="modal-title">提示</view>
           <view class="modal-message">删除该商品?</view>
           <view class="modal-buttons">
             <button class="modal-btn cancel-btn" @click="cancelDelete">取消</button>
             <button class="modal-btn confirm-btn" @click="confirmDelete">确认</button>
           </view>
         </view>
       </view>
       
       <!-- 优惠明细弹窗 -->
       <view class="discount-modal" v-if="showDiscountModal">
         <view class="discount-overlay" @click="closeDiscountModal"></view>
         <view class="discount-content">
           <view class="discount-header">
             <text class="discount-title">优惠明细</text>
             <text class="discount-close" @click="closeDiscountModal">×</text>
           </view>
           <view class="discount-list">
             <view class="discount-item">
               <text class="discount-label">商品总额</text>
               <text class="discount-value">¥{{ totalPrice.toFixed(2) }}</text>
             </view>
             <view class="discount-item">
               <text class="discount-label">优惠券</text>
               <text class="discount-value">- ¥0.00</text>
             </view>
             <view class="discount-item">
               <text class="discount-label">其他优惠</text>
               <text class="discount-value">- ¥{{ discount.toFixed(2) }}</text>
             </view>
           </view>
         </view>
       </view>
    </template>
  </view>
</template>

<script>
import { get, post, put, del } from '@/config/request.js'
import { getCurrentMemberId, getMemberIdFromCartList } from '@/utils/userState.js'

export default {
  data() {
    return {
      cartList: [], // 购物车数据，从后端获取
      loading: false, // 加载状态
      error: null, // 错误信息
      showDeleteModal: false,
      deleteItemId: null,
      startX: 0,
      currentX: 0,
      isSliding: false,
      currentSlideIndex: -1,
      showDiscountModal: false,
    }
  },
  
  // 生命周期钩子
  onLoad() {
    this.fetchCartData()
  },
  
  onShow() {
    // 页面显示时刷新购物车数据
    this.fetchCartData()
  },
  
  onPullDownRefresh() {
    // 下拉刷新
    this.fetchCartData().finally(() => {
      uni.stopPullDownRefresh()
    })
  },
  
  computed: {
    // 按店铺分组商品
    groupedStores() {
      const stores = {}
      this.cartList.forEach(item => {
        if (!stores[item.storeName]) {
          stores[item.storeName] = {
            name: item.storeName,
            items: [],
            promotion: item.promotion
          }
        }
        stores[item.storeName].items.push(item)
      })
      
      // 计算每个店铺的选中状态
      Object.values(stores).forEach(store => {
        // 店铺选中 = 该店铺下所有商品都选中
        store.checked = store.items.length > 0 && store.items.every(item => item.checked)
      })
      
      return Object.values(stores)
    },
    selectAll: {
      get() {
        return this.cartList.every((item) => item.checked)
      },
      set(value) {
        this.cartList.forEach((item) => {
          item.checked = value
        })
      },
    },
    totalPrice() {
      return this.cartList.reduce((total, item) => {
        return item.checked ? total + item.lastprice * item.count : total
      }, 0)
    },
    discount() {
      // 模拟优惠计算
      return this.totalPrice > 20000 ? 100 : 0
    },
    selectedCount() {
      return this.cartList.filter((item) => item.checked).length
    },
  },
  
  methods: {
         // 获取购物车数据
     async fetchCartData() {
       this.loading = true
       this.error = null
       
       try {
         console.log('开始获取购物车数据...')
         
         // 检查用户是否已登录
         const currentMemberId = getCurrentMemberId()
         if (!currentMemberId) {
           this.error = '请先登录'
           this.cartList = []
           return
         }
         
         console.log('当前用户memberId:', currentMemberId)
         console.log('请求URL:', '/cart/list')
          
         const response = await get('/cart/list', { memberId: currentMemberId })
         console.log('API响应:', response)
         
         if (response.code === 200) {
           // 处理返回的数据，确保数据结构一致
           const allCartItems = response.rows.map(item => ({
             id: item.id,
             storeName: item.shopName || '默认店铺',
             name: item.productName || '商品名称',
             spec: item.description || '',
             unit: item.productUnit || '',
             lastprice: parseFloat(item.currentPrice) || parseFloat(item.cartPrice) || 0,
			 cartprice:parseFloat(item.cartPrice) || 0,
             count: parseInt(item.quantity) || 1,
             image: item.mainImage || '/static/img/背景.png',
             checked: item.selected === 1,
             offsetX: 0,
             promotion: '',
             memberId: item.memberId // 添加memberId字段
           }))
           
           console.log('处理后的所有购物车数据:', allCartItems)
           
           // 只显示当前用户的购物车数据
           this.cartList = allCartItems.filter(item => {
             const itemMemberId = parseInt(item.memberId)
             const isMatch = itemMemberId === currentMemberId
             console.log(`商品ID ${item.id}: item.memberId=${item.memberId}(${typeof item.memberId}), 转换为数字=${itemMemberId}, currentMemberId=${currentMemberId}, 是否匹配=${isMatch}`)
             return isMatch
           })
           
           console.log('过滤后的购物车数据:', this.cartList)
         } else {
           this.error = response.msg || '获取购物车数据失败'
           console.error('API返回错误:', response)
         }
       } catch (err) {
         console.error('获取购物车数据失败:', err)
         if (err.message === '用户未登录') {
           this.error = '请先登录'
         } else {
           this.error = '网络错误，请检查网络连接'
         }
         this.cartList = []
       } finally {
         this.loading = false
       }
     },
    
    // 更新商品数量
    async updateQuantity(itemId, newCount) {
      try {
        // 获取当前用户ID
        const currentMemberId = getCurrentMemberId()
        if (!currentMemberId) {
          uni.showToast({ title: '请先登录', icon: 'none' })
          return
        }
        
        // 查找购物车项，确保属于当前用户
        const cartItem = this.cartList.find(item => item.id === itemId)
        if (!cartItem) {
          uni.showToast({ title: '购物车项不存在', icon: 'none' })
          return
        }
        
        // 验证购物车项是否属于当前用户
        if (parseInt(cartItem.memberId) !== currentMemberId) {
          uni.showToast({ title: '无权限修改此购物车项', icon: 'none' })
          return
        }
        
        console.log('准备更新购物车数量:', {
          id: itemId,
          quantity: newCount,
          memberId: currentMemberId
        })
        
        // 构建请求头，确保包含用户身份信息
        const headers = {
          'X-User-Id': currentMemberId,
          'X-Member-Id': currentMemberId
        }
        
        const response = await put('/cart', {
          id: itemId,
          quantity: newCount,
          memberId: currentMemberId
        }, { headers })
        
        if (response.code === 200) {
          // 更新本地数据
          const itemIndex = this.cartList.findIndex(item => item.id === itemId)
          if (itemIndex !== -1) {
            this.cartList[itemIndex].count = newCount
          }
          console.log('数量更新成功')
        } else {
          console.error('API返回错误:', response)
          uni.showToast({ title: response.msg || '更新失败', icon: 'none' })
        }
      } catch (err) {
        console.error('更新数量失败:', err)
        uni.showToast({ title: '网络错误，请重试', icon: 'none' })
        // 恢复原数量
        this.fetchCartData()
      }
    },
    
    // 删除购物车商品
    async deleteCartItem(itemId) {
      try {
        // 获取当前用户ID
        const currentMemberId = getCurrentMemberId()
        if (!currentMemberId) {
          uni.showToast({ title: '请先登录', icon: 'none' })
          return
        }
        
        // 查找购物车项，确保属于当前用户
        const cartItem = this.cartList.find(item => item.id === itemId)
        if (!cartItem) {
          uni.showToast({ title: '购物车项不存在', icon: 'none' })
          return
        }
        
        // 验证购物车项是否属于当前用户
        if (parseInt(cartItem.memberId) !== currentMemberId) {
          uni.showToast({ title: '无权限删除此购物车项', icon: 'none' })
          return
        }
        
        console.log('准备删除购物车项:', {
          id: itemId,
          memberId: currentMemberId
        })
        
        // 构建请求头，确保包含用户身份信息
        const headers = {
          'X-User-Id': currentMemberId,
          'X-Member-Id': currentMemberId
        }
        
        const response = await del(`/cart/${itemId}`, {
          memberId: currentMemberId
        }, { headers })
        
        if (response.code === 200) {
          // 从本地数据中移除
          const itemIndex = this.cartList.findIndex(item => item.id === itemId)
          if (itemIndex !== -1) {
            this.cartList.splice(itemIndex, 1)
          }
          uni.showToast({ title: '删除成功', icon: 'success' })
        } else {
          console.error('API返回错误:', response)
          uni.showToast({ title: response.msg || '删除失败', icon: 'none' })
        }
      } catch (err) {
        console.error('删除失败:', err)
        uni.showToast({ title: '网络错误，请重试', icon: 'none' })
      }
    },
    
    // 触摸事件处理
    handleTouchStart(e, itemId) {
      const itemIndex = this.cartList.findIndex(item => item.id === itemId)
      if (itemIndex === -1) return
      
      if (this.currentSlideIndex !== -1 && this.currentSlideIndex !== itemIndex) {
        this.cartList[this.currentSlideIndex].offsetX = 0
      }
      this.currentSlideIndex = itemIndex
      this.startX = e.touches[0].clientX
      this.isSliding = true
    },
    handleTouchMove(e, itemId) {
      if (!this.isSliding) return

      const itemIndex = this.cartList.findIndex(item => item.id === itemId)
      if (itemIndex === -1) return

      this.currentX = e.touches[0].clientX
      const diffX = this.startX - this.currentX
      const maxSlide = 80 // 最大滑动距离

      // 左滑
      if (diffX > 0) {
        this.cartList[itemIndex].offsetX = -Math.min(diffX, maxSlide)
      }
      // 右滑
      else if (this.cartList[itemIndex].offsetX < 0) {
        this.cartList[itemIndex].offsetX = Math.max(-maxSlide, this.cartList[itemIndex].offsetX - diffX / 2)
      }

      // 阻止页面滚动
      if (Math.abs(diffX) > 5) {
        e.preventDefault()
      }
    },
    handleTouchEnd(itemId) {
      this.isSliding = false
      const itemIndex = this.cartList.findIndex(item => item.id === itemId)
      if (itemIndex === -1) return
      
      const threshold = 40 // 滑动阈值

      if (this.cartList[itemIndex].offsetX < -threshold) {
        this.cartList[itemIndex].offsetX = -80 // 完全显示删除按钮
      } else {
        this.cartList[itemIndex].offsetX = 0 // 复位
      }
    },

    // 商品操作
    showDeleteConfirm(itemId) {
      this.deleteItemId = itemId
      this.showDeleteModal = true
    },
    
    confirmDelete() {
      if (this.deleteItemId) {
        this.deleteCartItem(this.deleteItemId)
        this.showDeleteModal = false
        this.deleteItemId = null
      }
    },
    
    cancelDelete() {
      this.showDeleteModal = false
      this.deleteItemId = null
    },
    
    // 显示优惠明细弹窗
    showDiscountDetail() {
      this.showDiscountModal = true
    },
    
    // 关闭优惠明细弹窗
    closeDiscountModal() {
      this.showDiscountModal = false
    },

    // 全选/反选
    handleSelectAll(checked) {
      this.cartList.forEach((item) => {
        item.checked = checked
      })
      
      // 更新所有店铺的选中状态
      this.updateAllStoreSelection()
    },

    // 数量控制
    decreaseQuantity(itemId) {
      const itemIndex = this.cartList.findIndex(item => item.id === itemId)
      if (itemIndex !== -1 && this.cartList[itemIndex].count > 1) {
        const newCount = this.cartList[itemIndex].count - 1
        this.updateQuantity(itemId, newCount)
      } else if (itemIndex !== -1 && this.cartList[itemIndex].count <= 1) {
        uni.showToast({ title: '最小数量为1', icon: 'none' })
      }
    },
    
    increaseQuantity(itemId) {
      const itemIndex = this.cartList.findIndex(item => item.id === itemId)
      if (itemIndex !== -1) {
        if (this.cartList[itemIndex].count < 999) {
          const newCount = this.cartList[itemIndex].count + 1
          this.updateQuantity(itemId, newCount)
        } else {
          uni.showToast({ title: '最大数量为999', icon: 'none' })
        }
      }
    },
    
    // 处理数量输入
    onQuantityInput(event, itemId) {
      const value = event.target.value
      const itemIndex = this.cartList.findIndex(item => item.id === itemId)
      if (itemIndex !== -1) {
        // 只允许输入数字
        if (/^\d*$/.test(value)) {
          const numValue = parseInt(value) || 0
          // 限制最小值为1，最大值为999
          if (numValue >= 1 && numValue <= 999) {
            this.cartList[itemIndex].count = numValue
          } else if (numValue > 999) {
            this.cartList[itemIndex].count = 999
            uni.showToast({ title: '最大数量为999', icon: 'none' })
          }
        }
      }
    },
    
    // 处理数量输入框失去焦点
    onQuantityBlur(itemId) {
      const itemIndex = this.cartList.findIndex(item => item.id === itemId)
      if (itemIndex !== -1) {
        // 确保数量至少为1
        if (this.cartList[itemIndex].count < 1) {
          this.cartList[itemIndex].count = 1
        }
        // 同步到后端
        this.updateQuantity(itemId, this.cartList[itemIndex].count)
      }
    },

         // 结算
     handleCheckout() {
       if (this.selectedCount === 0) {
         uni.showToast({ title: '请选择商品', icon: 'none' })
         return
       }
       
       // 获取选中的商品
       const selectedItems = this.cartList.filter(item => item.checked)
       
       // 计算总价
       const totalPrice = selectedItems.reduce((total, item) => {
         return total + item.lastprice * item.count
       }, 0)
       
       // 计算优惠金额
       const discount = totalPrice > 20000 ? 100 : 0
       
       console.log('准备跳转到填写订单页面，选中的商品:', selectedItems)
       console.log('总价:', totalPrice, '优惠:', discount)
       
       // 传递数据到填写订单页面
       const url = `/pages/tianxiedingdan/tianxiedingdan?items=${encodeURIComponent(JSON.stringify(selectedItems))}&totalPrice=${totalPrice}&discount=${discount}`
       console.log('跳转URL:', url)
       
       uni.navigateTo({
         url: url,
         success: () => {
           console.log('跳转成功')
         },
         fail: (err) => {
           console.error('跳转失败:', err)
           uni.showToast({ title: '页面跳转失败', icon: 'none' })
         }
       })
     },
    
         // 切换店铺选择状态
     toggleStore(storeIndex, checked) {
       const store = this.groupedStores[storeIndex]
       if (store) {
         // 更新店铺下所有商品的选中状态
         store.items.forEach(item => {
           item.checked = checked
         })
         
         // 更新购物车列表中的对应商品
         store.items.forEach(storeItem => {
           const cartItem = this.cartList.find(cartItem => cartItem.id === storeItem.id)
           if (cartItem) {
             cartItem.checked = checked
           }
         })
       }
     },
    
         // 切换商品选择状态
     toggleProduct(itemId, checked) {
       const item = this.cartList.find(item => item.id === itemId)
       if (item) {
         item.checked = checked
         
         // 更新店铺选中状态
         this.updateStoreSelection(item.storeName)
       }
     },
    
    // 跳转到领券中心
    goToCouponCenter() {
      uni.navigateTo({
        url: '/pages/lingquanzhongxin/lingquanzhongxin'
      })
    },
    
    // 跳转到店铺页面
    goToStore(storeName) {
      uni.navigateTo({
        url: `/pages/dianpu/dianpu?storeName=${encodeURIComponent(storeName)}`
      })
    },
    
         // 跳转到首页
     toshouye() {
       uni.switchTab({
         url: '/pages/index/index'
       })
     },
     
     // 更新指定店铺的选中状态
     updateStoreSelection(storeName) {
       // 店铺选中状态会在 computed 中自动计算，这里不需要手动更新
       // 但可以触发视图更新
       this.$forceUpdate()
     },
     
     // 更新所有店铺的选中状态
     updateAllStoreSelection() {
       // 所有店铺的选中状态会在 computed 中自动计算，这里不需要手动更新
       // 但可以触发视图更新
       this.$forceUpdate()
     },
     


  },
}
</script>

<style scoped>
.cart-container {
  padding-bottom: 170px;
  background-color: #f7f7f7;
  /* 兼容性处理 */
  min-height: 100vh;
  position: relative;
}

/* 加载状态样式 */
.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 300px;
  background-color: #fff;
  border-radius: 12px;
  margin: 20px;
}

.loading-text {
  margin-top: 15px;
  font-size: 14px;
  color: #999;
}

/* 错误状态样式 */
.error-container {
  padding: 40px 20px;
  text-align: center;
}

.error-text {
  display: block;
  margin: 15px 0;
  font-size: 14px;
  color: #666;
}

.retry-btn {
  background-color: #ff4444;
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 8px 20px;
  font-size: 14px;
  margin-top: 10px;
}



 .cart-list {
   padding: 10px;
 }

 /* 店铺区域 */
 .store-section {
   background-color: #fff;
   border-radius: 12px;
   margin-bottom: 15px;
   overflow: hidden;
   box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
 }

 .store-header {
   display: flex;
   justify-content: space-between;
   align-items: center;
   padding: 15px 20px;
   border-bottom: 1px solid #f0f0f0;
 }

 .store-info {
   display: flex;
   align-items: center;
 }

   .store-name {
    font-size: 16px;
    color: #333;
    margin-left: 10px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
  }
  
  .store-name:active {
    color: #ff4444;
    transform: scale(0.98);
  }

 .get-coupon-btn {
   font-size: 14px;
   color: #ff4444;
   padding: 6px 12px;
   cursor: pointer;
   transition: all 0.3s ease;
 }
 
 .get-coupon-btn:active {
   background-color: #ff4444;
   color: #fff;
   transform: scale(0.95);
 }

 /* 满减活动信息 */
 .promotion-info {
   background-color: #fff5f5;
   padding: 12px 20px;
   display: flex;
   align-items: center;
 }

 .promotion-tag {
   background-color: #ff4444;
   color: #fff;
   font-size: 12px;
   padding: 4px 8px;
   border-radius: 10px;
   margin-right: 10px;
   white-space: nowrap;
 }

 .promotion-scroll {
   flex: 1;
   white-space: nowrap;
 }

 .promotion-desc {
   font-size: 14px;
   color: #666;
 }

 /* 商品项 */
 .product-item {
   position: relative;
   height: 120px;
   overflow: hidden;
   border-bottom: 1px solid #f0f0f0;
 }

 .product-item:last-child {
   border-bottom: none;
 }

.item-content {
  position: absolute;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  padding: 10px;
  box-sizing: border-box;
  background-color: #fff;
  transition: transform 0.3s cubic-bezier(0.18, 0.89, 0.32, 1);
  z-index: 2;
}

.item-checkbox {
  margin-right: 10px;
}

 .item-image {
   width: 80px;
   height: 80px;
   border-radius: 8px;
   margin-right: 15px;
 }

.item-info {
  flex: 1;
  display: flex;
  flex-direction: column;
}

 .item-title {
   font-size: 14px;
   color: #333;
   margin-bottom: 4px;
   display: -webkit-box;
   -webkit-box-orient: vertical;
   -webkit-line-clamp: 2;
   overflow: hidden;
   line-height: 1.3;
 }

 .item-spec {
   font-size: 12px;
   color: #999;
   margin-bottom: 4px;
 }
 
 .item-unit {
   font-size: 12px;
   color: #999;
   margin-bottom: 8px;
 }

 .item-price {
   font-size: 18px;
   color: #ff4444;
   font-weight: bold;
   margin-top: 4px;
 }

 .item-actions {
   margin-left: 15px;
   display: flex;
   align-items: center;
 }
 
 /* 数量控制 */
 .quantity-control {
   display: flex;
   align-items: center;
   background-color: #f8f8f8;
   border-radius: 20px;
   padding: 4px;
 }
 
 .quantity-btn {
   width: 22px;
   height: 22px;
   display: flex;
   align-items: center;
   justify-content: center;
   background-color: #fff;
   border-radius: 50%;
   font-size: 12px;
   color: #666;
   box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
 }
 
   .quantity-input {
    width: 35px;
    text-align: center;
    font-size: 13px;
    color: #333;
    font-weight: 500;
    background-color: #fff;
    border-radius: 8px;
    margin: 0 4px;
    padding: 3px 0;
    border: none;
    outline: none;
  }
  
  .quantity-input:focus {
    background-color: #f0f0f0;
  }

.delete-btn {
  position: absolute;
  right: -80px;
  top: 0;
  width: 80px;
  height: 100%;
  background-color: #ff5000;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  z-index: 1;
  transition: transform 0.3s cubic-bezier(0.18, 0.89, 0.32, 1);
}

.footer-bar {
  position: fixed;
  bottom: 50px;
  left: 0;
  right: 0;
  height: 50px;
  display: flex;
  align-items: center;
  background-color: #fff;
  border-top: 1px solid #eee;
  padding: 0 15px;
  box-sizing: border-box;
  z-index: 1000;
  /* 兼容性处理 */
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
}

.footer-left {
  flex: 1;
}

.footer-right {
  display: flex;
  align-items: center;
}

.total-price {
  font-size: 16px;
  color: #ff5000;
  font-weight: bold;
  margin-right: 10px;
}

 .discount {
   font-size: 12px;
   color: #999;
   margin-right: 10px;
 }
 
 .discount-detail {
   font-size: 12px;
   color: #999;
   text-decoration: underline;
   margin-right: 15px;
 }

 .submit-btn {
   background: linear-gradient(135deg, #ff4443, #ff6666);
   color: #fff;
   border: none;
   border-radius: 25px;
   padding: 0 30px;
   height: 40px;
   line-height: 40px;
   font-size: 14px;
   font-weight: bold;
   box-shadow: 0 2px 10px rgba(255, 68, 68, 0.3);
   /* 兼容性处理 */
   display: inline-block;
   text-align: center;
   vertical-align: middle;
   cursor: pointer;
   -webkit-appearance: none;
   -moz-appearance: none;
   appearance: none;
   /* 确保按钮可见 */
   min-width: 80px;
   white-space: nowrap;
   overflow: visible;
 }

 .submit-btn[disabled] {
   background-color: #ffb088;
   cursor: not-allowed;
 }
 
 /* 删除确认弹窗样式 */
 .delete-modal {
   position: fixed;
   top: 0;
   left: 0;
   right: 0;
   bottom: 0;
   z-index: 9999;
   display: flex;
   align-items: center;
   justify-content: center;
 }
 
 .modal-overlay {
   position: absolute;
   top: 0;
   left: 0;
   right: 0;
   bottom: 0;
   background-color: rgba(0, 0, 0, 0.5);
 }
 
 .modal-content {
   position: relative;
   background-color: #fff;
   border-radius: 12px;
   width: 280px;
   padding: 20px;
   box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
 }
 
 .modal-title {
   font-size: 18px;
   font-weight: bold;
   color: #333;
   text-align: center;
   margin-bottom: 15px;
 }
 
 .modal-message {
   font-size: 16px;
   color: #666;
   text-align: center;
   margin-bottom: 20px;
 }
 
 .modal-buttons {
   display: flex;
   justify-content: space-between;
   gap: 15px;
 }
 
 .modal-btn {
   flex: 1;
   height: 40px;
   border: none;
   border-radius: 6px;
   font-size: 16px;
   font-weight: 500;
   cursor: pointer;
 }
 
 .cancel-btn {
   background-color: #f5f5f5;
   color: #333;
 }
 
 .confirm-btn {
   background-color: #ff4444;
   color: #fff;
 }
 
 /* 优惠明细弹窗样式 */
 .discount-modal {
   position: fixed;
   top: 0;
   left: 0;
   right: 0;
   bottom: 0;
   z-index: 9999;
   display: flex;
   align-items: flex-end;
   justify-content: center;
 }
 
 .discount-overlay {
   position: absolute;
   top: 0;
   left: 0;
   right: 0;
   bottom: 0;
   background-color: rgba(0, 0, 0, 0.5);
 }
 
 .discount-content {
   position: relative;
   background-color: #fff;
   border-radius: 12px 12px 0 0;
   width: 100%;
   max-width: 400px;
   padding: 20px;
   box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.2);
   margin-bottom: 0;
 }
 
 .discount-header {
   display: flex;
   justify-content: space-between;
   align-items: center;
   margin-bottom: 20px;
   padding-bottom: 15px;
   border-bottom: 1px solid #f0f0f0;
 }
 
 .discount-title {
   font-size: 18px;
   font-weight: bold;
   color: #333;
 }
 
 .discount-close {
   font-size: 24px;
   color: #999;
   cursor: pointer;
   width: 30px;
   height: 30px;
   display: flex;
   align-items: center;
   justify-content: center;
 }
 
 .discount-list {
   display: flex;
   flex-direction: column;
   gap: 15px;
 }
 
 .discount-item {
   display: flex;
   justify-content: space-between;
   align-items: center;
   padding: 10px 0;
 }
 
 .discount-label {
   font-size: 16px;
   color: #333;
 }
 
 .discount-value {
   font-size: 16px;
   color: #333;
   font-weight: 500;
 }
 .item-cartprice{
	 font-size: 13px;
	 color: #999;
	 margin-left: 4px ;
 }

</style>
